package com.doudou.oauth.config.validate;

import com.doudou.oauth.validate.ValidateCodeGenerator;
import com.doudou.oauth.validate.image.ImageCodeGenerator;
import com.doudou.oauth.validate.properties.CustomSecurityProperties;
import com.doudou.oauth.validate.sms.DefaultSmsCodeSender;
import com.doudou.oauth.validate.sms.SmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: 图形验证码生成器配置bean
 * @description
 * @author: 傻男人
 * @create: 2019-10-23 13:44
 **/
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private CustomSecurityProperties customSecurityProperties;

    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator(){
        ImageCodeGenerator imageCodeGenerator = new ImageCodeGenerator();
        imageCodeGenerator.setCodeProperties(customSecurityProperties);
        return imageCodeGenerator;
    }

    @Bean
    @ConditionalOnMissingBean(SmsCodeSender.class)
    public SmsCodeSender smsCodeSender(){
        return new DefaultSmsCodeSender();
    }
}
